package com.ysxsoft.wdg.ui.activity.th.tuan;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.widget.NestedScrollView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.youth.banner.Banner;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.util.ViewUtils;

import butterknife.BindView;
import butterknife.OnClick;
import cn.iwgang.countdownview.CountdownView;

public class TuanGoodsDetailActivity extends BaseActivity {

    public static void start(Context context,String detail_id){
        Intent intent = new Intent(context,TuanGoodsDetailActivity.class);
        intent.putExtra("detail_id",detail_id);
        context.startActivity(intent);
    }

    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.tv_home)
    TextView tvHome;
    @BindView(R.id.tv_collect)
    TextView tvCollect;
    @BindView(R.id.tv_one_buy)
    TextView tvOneBuy;
    @BindView(R.id.tv_tuan_buy)
    TextView tvTuanBuy;
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_old_money)
    TextView tvOldMoney;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_centent)
    TextView tvCentent;
    @BindView(R.id.tv_attention)
    TextView tvAttention;
    @BindView(R.id.iv_price)
    ImageView ivPrice;
    @BindView(R.id.iv_tx)
    ImageView ivTx;
    @BindView(R.id.tv_nick)
    TextView tvNick;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.tv_people_num)
    TextView tvPeopleNum;
    @BindView(R.id.countDown)
    CountdownView countDown;
    @BindView(R.id.iv_tx2)
    ImageView ivTx2;
    @BindView(R.id.tv_nick2)
    TextView tvNick2;
    @BindView(R.id.tv_location2)
    TextView tvLocation2;
    @BindView(R.id.tv_people_num2)
    TextView tvPeopleNum2;
    @BindView(R.id.countDown2)
    CountdownView countDown2;
    @BindView(R.id.ll_jion_v)
    LinearLayout llJionV;
    @BindView(R.id.iv_pl_tx)
    ImageView ivPlTx;
    @BindView(R.id.tv_pl_nick)
    TextView tvPlNick;
    @BindView(R.id.tv_pl_content)
    TextView tvPlContent;
    @BindView(R.id.webView)
    WebView webView;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    @BindView(R.id.btn_cart)
    ImageView btnCart;
    @BindView(R.id.title)
    RelativeLayout title;



    private int bannerHeight;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_tuan_goods_detail;
    }

    @Override
    protected void initData() {
        initStatusBar(topView, false);
        btnCart.setVisibility(View.GONE);

        ivPrice.setImageResource(R.mipmap.th_ptj);
        ViewUtils.setDeletLine(tvOldMoney);

    }

    @Override
    protected void setListener() {
        // 获取顶部图片高度后，设置滚动监听
        ViewTreeObserver vto = banner.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                banner.getViewTreeObserver().removeGlobalOnLayoutListener(
                        this);
                bannerHeight = banner.getHeight();
            }
        });

        scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int x, int y, int oldScrollX, int oldScrollY) {
                if (y <= 0) {
                    title.setBackgroundColor(Color.parseColor("#00000000"));
                } else if (y > 0 && y <= bannerHeight) {
                    float scale = (float) y / bannerHeight;
                    float alpha = (255 * scale);
                    // 只是layout背景透明
                    title.setBackgroundColor(Color.argb((int) alpha, 254, 74, 112));
                } else {
                    title.setBackgroundColor(Color.parseColor("#fe4a70"));
                }
            }
        });
    }

    @OnClick({R.id.tv_home, R.id.tv_phone, R.id.tv_collect,
            R.id.tv_one_buy, R.id.tv_tuan_buy, R.id.ll_2_jion,
            R.id.iv_pt_intro, R.id.ll_jion1, R.id.ll_jion2,
            R.id.ll_2_pl, R.id.btn_finish, R.id.btn_share})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_home://返回首页
                break;
            case R.id.tv_phone://联系客服
                break;
            case R.id.tv_collect://收藏
                break;
            case R.id.tv_one_buy://单独购买
                break;
            case R.id.tv_tuan_buy://发起拼单
                break;
            case R.id.ll_2_jion://团购列表  查看全部
                TuanListActivity.start(mContext,"");
                break;
            case R.id.iv_pt_intro://拼团介绍
                TuanIntroActivity.start(mContext);
                break;
            case R.id.ll_jion1://第一个团
                PTuanDetailActivity.start(mContext);
                break;
            case R.id.ll_jion2://第二个团
                break;
            case R.id.ll_2_pl://宝贝评价  查看全部
                break;
            case R.id.btn_finish:
                finish();
                break;
            case R.id.btn_share://分享
                break;
        }
    }

}
